﻿using System;
using System.Collections.Generic;
using System.Text;

using TRPOP.CMS.Model;
using TRPOP.CMS.DALFactory;
using TRPOP.Common;

namespace TRPOP.CMS.Business
{
    public class AdvshitManage
    {

        private IAdvshitDAL Idal;
        public AdvshitManage()
        {
            Idal = DataAccess.CreateadvshitDAL();
        }

        #region 保存 Save
        ///	<summary>
        ///	保存
        ///	</summary>
        ///	<param name="AdvshitInfo"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult Save(AdvshitInfo info)
        {
            return Idal.Save(info);
        }

        #endregion

        #region 获取实体 GetInfoById
        ///	<summary>
        ///	获取实体
        ///	</summary>
        ///	<param name="hID"></param>
        ///	<returns>AdvshitInfo</returns>
        public AdvshitInfo GetInfoById(int id)
        {
            return Idal.GetInfoById(id);
        }
        #endregion

        #region 删除 DeleteInfoById
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="id"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoById(int id)
        {
            return Idal.DeleteInfoByIds(id.ToString());
        }
        #endregion

        #region 删除 DeleteInfoByIds
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="ids"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoByIds(string ids)
        {
            return Idal.DeleteInfoByIds(ids);
        }
        #endregion

        #region 自定义列表（无分页） GetListByCondition
        ///	<summary>
        ///	自定义列表（无分页）
        ///	</summary>
        ///	<param name="topn">前N条，为0时表示所有符合条件的</param>
        ///	<param name="condition">自定义条件，要以And开头</param>
        ///	<param name="orderby">排序，不需要Order by </param>
        ///	<returns>List<AdvshitInfo></returns>
        public List<AdvshitInfo> GetListByCondition(int topn, string condition, string orderby)
        {
            return Idal.GetListByCondition(topn, condition, orderby);
        }
        #endregion

        #region 自定义列表（分页） GetListByPager
        ///	<summary>
        ///	自定义列表（分页）
        ///	</summary>
        ///	<returns>List<AdvshitInfo></returns>
        public List<AdvshitInfo> GetListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            return Idal.GetListByPager(pageNumber, pageSize, condition, orderby, out  recordCount);
        }
        #endregion

        #region 统计列表
        /// <summary>
        /// 点击统计列表
        /// </summary>
        /// <param name="adID">广告Id</param>
        /// <param name="beginTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="IP">IP</param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public List<AdvshitInfo> GetListByAdID(int adID,DateTime beginTime,DateTime endTime,string IP,  int pageNumber, int pageSize,  out int recordCount)
        {
           string condition="";
           string orderby = "";
           IP = IP.Replace("'","");
           recordCount = 0;
           if (adID > 0)
           {
               condition += " AND AdID=" + adID;

               if (beginTime !=  StringExtension.NullDateTime)
               {
                   condition += " AND AddTime>='"+beginTime+"'";
               }

               if (endTime != StringExtension.NullDateTime)
               {
                   condition += "   AND AddTime<='"+endTime+"'";
               }

               if (IP != "")
               {
                   condition += " AND IP='"+IP+"'";
               }

               return GetListByPager(pageNumber, pageSize, condition, orderby, out recordCount);
           }
           else
           {
               return null;
           }
        }
        #endregion


    }
}
